<%@page import="org.springframework.scheduling.annotation.Scheduled"%>
<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String moifyUserId = user.getUsername();
	DutyForm form = (DutyForm) request.getAttribute("command");
	String editSiteId = form.getSiteId();
	String editDeptId = form.getDeptId();
	String backDutyDate = form.getDutyDate();
	String pageNum = form.getPageNum();
	TblOaDuty duty = (TblOaDuty) request.getAttribute("duty");
	String siteId = duty.getSiteId();
	String deptId = duty.getDeptId();
	String userId = duty.getUserId();
	String dutyId = duty.getDutyId();
	String scheduleId = duty.getScheduleId();
	String userTelNo = duty.getUserTelNo();
	String dutyDate = DateFormatUtils.format(duty.getDutyDate(), "yyyy-MM-dd");
%>

<style>
	.selectHour-split{
		padding:0 2px;
		margin-right:5px;	
	}
	.selectMinute-split{
		padding:0 2px;
	}
</style>

<div>
	<form id="editDutyForm" target="_coreIframe" method="post" action="<%=request.getContextPath()%>/duty/doEditDuty" 
		onsubmit="return submitTelNo()" enctype="multipart/form-data">
		<div class="breadcrumb">
			<div class="bcIcon"></div>
			<ul class="bcNav">
				<li>值班管理</li>
			</ul>
		</div>
		<table class="formTable">
			<tr>
				<td class="tdTitle">所属公司：</td>
				<td>
					<select id="siteList" class="easyui-combobox" name="siteId" style="width:100px;"></select>
					<span class="errorTipWrap" id="errorTip_siteid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">部门：</td>
				<td>
					<select id="deptList" class="easyui-combobox" name="deptId" style="width:100px;"></select>
					<span class="errorTipWrap" id="errorTip_deptid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">员工：</td>
				<td>
					<select id="userList" class="easyui-combobox" name="userId" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">值班日期：</td>
				<td>
				<input class="inputText xxs" type="text" name="dutyDate" value="<%=dutyDate%>" style="width:200px;" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">值班班次：</td>
				<td>
					<select id="scheduleList" class="easyui-combobox" name="scheduleId" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">电话：</td>
				<td>
					<select id="telNo" class="easyui-combobox" name="userTelNo" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle"></td>
				<td>
					<div>
						<input class="input-btn-microsoft" type="submit" value="提交">
						<a class="a-btn-microsoft" href="javascript:XF.Duty.manageDuty()">取消</a>
					</div>
				</td>
			</tr>
		</table>
		<input type="hidden" value="<%=EncrypTool.encode(dutyId+"") %>" name="dutyId"> 	
		<input type="hidden" value="<%=moifyUserId %>" name="moifyUserId">
		<input type="hidden" value="<%=editSiteId %>" name="editSiteId">
		<input type="hidden" value="<%=editDeptId %>" name="editDeptId">
		<input type="hidden" value="<%=backDutyDate %>" name="dutyDateStr">
		<input type="hidden" value="<%=pageNum %>" name="pageNum">
	</form>
	<iframe id="_coreIframe" name="_coreIframe" style="display: none;"></iframe>
</div>

<script>
$('#siteList').combobox({
	/* url:global.contextPath + '/company/siteList', */
	valueField:'siteid',
	textField:'sitename',
	/* missingMessage:'请选择所属类别', */
	disabled:true
});

$('#deptList').combobox({
	url:global.contextPath + '/duty/datagridDepts?siteId=' + '<%=siteId%>',
	valueField:'deptId',
	textField:'deptName',
	method:'get',
	editable:false,
	required: true,
	panelHeight: '300',
	onSelect:function(data){
		var deptId = data.deptId;
		var userurl = global.contextPath + '/duty/datagridUsers?siteId=' + '<%=siteId%>'+'&deptId='+deptId;
		var scheduleurl = global.contextPath + '/duty/datagridSchedules?siteId=' + '<%=siteId %>' + '&deptId='+ deptId;
		$("#userList").combobox('reload', userurl);
		$("#scheduleList").combobox('reload', scheduleurl);
	},
	onChange:function(){
		$("#userList").combobox('clear');
		$("#scheduleList").combobox('clear');
		$("#telNo").combobox('clear');
    }, 
});

$("#userList").combobox({
	url:global.contextPath + '/duty/datagridUsers?siteId=' + '<%=siteId%>'+'&deptId='+'<%=deptId%>',
	valueField:'userId',
	textField:'userName',
	method:'get',
	panelHeight: '300',
	required: true,
	editable:false,
	onSelect:function(data){
		var userId = data.userId;
		var telnourl = global.contextPath + '/duty/datagridTelNo?userId='+ userId;
		$("#telNo").combobox('reload', telnourl);
	},
	onChange:function(){
		$("#telNo").combobox('clear');
    }, 
});

$("#scheduleList").combobox({
	url:global.contextPath + '/duty/datagridSchedules?siteId=' + '<%=siteId %>' + '&deptId='+'<%=deptId %>',
	valueField:'scheduleId',
	textField:'scheduleName',
	editable:false,
	required: true
});

$("#telNo").combobox({
	url:global.contextPath + '/duty/datagridTelNo?userId=' + '<%=userId %>',
	valueField:'userId',
	textField:'telNo',
	editable:true,
	required:true
});

$('#siteList').combobox('setValue', '<%=siteId%>');
$('#siteList').combobox('setText', '<%=user.getSiteName()%>');
$('#deptList').combobox('setValue', '<%=deptId%>');
$('#userList').combobox('setValue', '<%=userId%>');
$('#scheduleList').combobox('setValue', '<%=scheduleId%>');
$('#telNo').combobox('setValue', '<%=userTelNo%>');

function submitTelNo(){
	$('#telNo').combobox('setValue',$('#telNo').combobox('getText'));
	return true;
}

</script>


			
